﻿using BlogDemo.Common;
using BlogDemo.Data;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace BlogDemo.Infrastructure
{
    public static class RepositoryExtensions
    {
        /// <summary>
        /// 查找符合特定表达式<see cref="TResult"/>列表
        /// </summary>
        /// <typeparam name="TEntity">实体类型</typeparam>
        /// <typeparam name="TResult">返回类型</typeparam>
        /// <param name="repository">仓储接口</param>
        /// <param name="predicate">查询条件谓语表达式</param>
        /// <param name="selector">筛选的字段表达式</param>
        /// <returns></returns>
        //public static IEnumerable<TResult> Query<TEntity,TResult>(this IRepository<TEntity> repository,
        //    Expression<Func<TEntity, bool>> predicate, 
        //    Expression<Func<TEntity, TResult>> selector) where TEntity : class, IEntity
        //{
        //   return  repository.Table.Where(predicate).Select(selector);
        //}
        ///// <summary>
        ///// 异步查找符合特定表达式<see cref="TResult"/>列表
        ///// </summary>
        ///// <typeparam name="TEntity">实体类型</typeparam>
        ///// <typeparam name="TResult">返回类型</typeparam>
        ///// <param name="repository">仓储接口</param>
        ///// <param name="predicate">查询条件谓语表达式</param>
        ///// <param name="selector">筛选的字段表达式</param>
        ///// <returns></returns>
        //public static async Task<IEnumerable<TResult>> QueryAsync<TEntity, TResult>(this IRepository<TEntity> repository,
        //    Expression<Func<TEntity, bool>> predicate,
        //    Expression<Func<TEntity, TResult>> selector) where TEntity : class, IEntity
        //{
        //    return await repository.Table.Where(predicate).Select(selector).ToListAsync();
        //}
    }
}
